package com.xlh.enums.user;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 性别
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@AllArgsConstructor
public enum SexEnum {

    MALE(1, "男"),
    FEMALE(2, "女");

    private Integer code;

    private String message;

    public static SexEnum getByCode(Integer code) {
        if (code == null) return null;
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getCode(), code)) {
                return sexEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(Integer code) {
        SexEnum sexEnum = getByCode(code);
        return sexEnum == null ? null : sexEnum.getMessage();
    }

    public static Integer getCodeByMessage(String message) {
        if (message == null) return null;
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getMessage(), message)) {
                return sexEnum.getCode();
            }
        }
        return null;
    }

}
